/**************************************************************
 * client.h - 
 * Copyright (c) 2009  Qin Xiaoxue  <crs.chin@gmail.com>
 *
 * This file is  free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
**************************************************************/


#if !defined(__CLIENT_H)
#define __CLIENT_H

#include <glib.h>
#include "configfile.h"

struct client{
  const  gchar *c_servername;
  void *c_data;

  /* standard playback controls */
  gboolean (*play)(void *data);
  gboolean (*stop)(void *data);
  gboolean (*pause)(void *data);
  gboolean (*toggle)(void *data);
  gboolean (*quit)(void *data);

  gboolean (*seek)(void *data, gint msec);
  gboolean (*seek_rel)(void *data, gint msec);

  /* volume range is supposed to be between 0 and 100 */
  gint     (*volume_get)(void *data, gint channel);
  gboolean (*volume_set)(void *data, gint channel, gint vol);

  gboolean (*next)(void *data);
  gboolean (*prev)(void *data);

  gint (*status)(void *data);  /* player status */
  gint (*time)(void *data);    /* current playing position in millisecond */
  gint (*duration)(void *data);    /* total playing time in millisecond */

  gchar *(*get_music_file)(void *data);
  gboolean (*play_music_file)(void *data, const gchar *filename);

  gboolean (*is_video)(void *data);
  gboolean (*set_subtitle)(void *data, const gchar *srt); /* for players playing video */

  /* music file meta info */
  gchar *(*get_artist)(void *data);
  gchar *(*get_title)(void *data);
  gchar *(*get_album)(void *data);
  gchar *(*get_year)(void *data);
  gchar *(*get_genre)(void *data);
  gchar *(*get_track)(void *data);
  gchar *(*get_comment)(void *data);

  gboolean (*set_artist)(void *data, const gchar *artist);
  gboolean (*set_title)(void *data, const gchar *title);
  gboolean (*set_album)(void *data, const gchar *album);
  gboolean (*set_year)(void *data, const gchar *year);
  gboolean (*set_genre)(void *data, const gchar *genre);
  gboolean (*set_track)(void *data, const gint *track);
  gboolean (*set_comment)(void *data, const gchar *comment);

  /* standard callbacks util functions  */
  gboolean (*set_file_changed)(void *data, void (*callback)(void *udata), void *udata);
  gboolean (*set_player_started)(void *data, void (*callback)(void *udata), void *udata);
  gboolean (*set_player_stoped)(void *data, void (*callback)(void *udata), void *udata);
  gboolean (*set_player_exited)(void *data, void (*callback)(void *udata), void *udata);

  gboolean (*get_option)(void *data, gint opt, void *result);
  gboolean (*set_option)(void *data, gint opt, void *optarg);

  gboolean (*is_error)(void *data);
  void (*clear_error)(void *data);
  void (*perror)(void *data);
};

/* for client->status return value */
enum __player_status{
  PLAYER_STATUS_STOP,
  PLAYER_STATUS_PLAY,
  PLAYER_STATUS_PAUSE
};

/* standard volume channels */
enum __channel{
  VOLUME_CHANNEL_ALL,
  VOLUME_CHANNEL_LEFT,
  VOLUME_CHANNEL_RIGHT
};

typedef struct client *(*client_init)(const gchar *client_name, const gchar *exec,
									  gint argc, gchar **argv);
typedef void           (*client_exit)(struct client *cl);


/*
 *this is the only structure the plugin have to export , and the symbol
 * name must be @plugin_descrip
 */
struct client_plugin_info{
  const client_init init;
  const client_exit exit;

  const gchar *player_name;
  const gchar *author;
  const gchar *version;
  const gchar *mail;
  const gchar *description;
};

struct client_plugin_info *load_client(const gchar *plugin);
struct client_plugin_info *load_client_file(const gchar *file);

gboolean  unload_client(const gchar *plugin, struct client *client);

struct client *load_and_init_client(const gchar *plugin, 
									const gchar *clientname,
									const gchar *exec,
									int argc, char **argv);

struct client *load_and_init_client_file(const gchar *file, 
										 const gchar *clientname,
										 const gchar *exec,
										 gchar **plugin_name,
										 int argc, char **argv);

gchar        **list_client(void);

#define CLIENT_EXPORT_SYMBOL_NAME  "plugin_descrip"
#define CLIENT_EXPORT_SYMBOL        plugin_descrip


#endif /*__CLIENT_H */
